$(function() {
	$("#photo").hide();
	statInputNum();
})

function statInputNum() {
	var max = 100, curLength;
	$("textarea").attr("maxlength", max);
	curLength = $("textarea").val().length;
	$("#count").text(curLength);
	$("textarea").on('input propertychange', function() {
		var _value = $(this).val().replace(/\n/gi, "");
		$("#count").text(_value.length);
	});
}

function save() {
	var type = $("#type").val();
	if (type == '0') {
		$.alert("请选择您要申请的服务");
		return false;
	}
	var reason = $("#reason").val();
	if (reason == '0') {
		$.alert("请选择您申请的原因");
		return false;
	}
	var exp = /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/;
	var applyAmount = null;
	var price = $("#price").val();
	if(price > 0){
		applyAmount = $("#applyAmount").val();
		if (!exp.test(applyAmount)) {
			$.alert("退款金额格式不正确");
			return false;
		} else{
			applyAmount = parseInt($("#applyAmount").val() * 100);
			if(applyAmount > price){
				$.alert("金额最高" + $("#amount").html() + "元");
				return false;
			}
		}
	}
	var remark = $("#remark").val();
	if (remark == '') {
		$.alert("请输入退款退货说明");
		return false;
	}
	$.showLoading();
	$.ajax({
		type : "post",
		url : appPath + "/buyer/addSalesReturn.html",
		data : {
			type : type,
			reason : reason,
			applyAmount : applyAmount,
			remark : $("#remark").val(),
			token : $.cookie("token"),
			goodsOrderIds : $("#goodsOrderIds").val(),
			imageUrl : $("#imageUrl").val()
		},
		success : function(result) {
			$.hideLoading();
			$.alert(result.msg, function() {
				if (result.code == '1') {
					gotoHtml('/order/detail.html?orderId=' + result.orderId);
				} else if (result.code == '-1') {
					window.location = appPath + "/member/login.html";
				}
			});
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			$.hideLoading();
			$.alert("系统异常，请稍后再试");
		}
	});
}
function selectfile(){
	$(".webuploader-element-invisible").trigger('click');
}